/*
给定一个整数数组 nums，将数组中的元素向右轮转 k 个位置，其中 k 是非负数。
*/
struct Solution {}
impl Solution {
    pub fn rotate(nums: &mut Vec<i32>, k: i32) {
        let len = nums.len();
        let k = k as usize % len;

        let mut temp_nums: Vec<i32> = vec![];
        for i in (len - k)..len {
            temp_nums.push(nums[i]);
        }

        for i in 0..(len - k) {
            let from = len - 1 - i - k;
            let to = len - 1 - i;
            nums[to] = nums[from];
        }

        for i in 0..temp_nums.len() {
            nums[i] = temp_nums[i];
        }
    }
}

pub fn main() {
    let mut nums = vec![1, 2, 3, 4, 5, 6, 7];
    Solution::rotate(&mut nums, 3);
    println!("{:?}", nums);
}
